<?php

include_once 'IterationStatement.php';

/**
 * Represents a foreach statement
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/ForEachStatementExample.php 
 */

class ForEachStatement extends IterationStatement
{
    /**
     * The ForEachStatement constructor
     * 
     * @param Expression $Group The array or object to be iterated
     * @param Expression $Element Variable(s) used to iterate through the elements of the object or array
     */
    
    public function __construct(Expression $Group = null, Expression $Element = null)
    {
        parent::__construct();
        
        is_null($Group) ?
            $this->Group = new Expression() :
            $this->set_Group($Group);
        
        is_null($Element) ?
            $this->Element = new Expression() :
            $this->set_Element($Element);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */

    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'Group')
        {
            $this->set_Group($value);
        }
        
        if($name == 'Element')
        {
            $this->set_Element($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'Group')
        {
            return $this->get_Group();
        }
        
        if ($name == 'Element')
        {
            return $this->get_Element();
        }
    }
    
    /**
     * The $Group getter method
     * @return Expression 
     */
    
    public function get_Group()
    {
        return $this->Group;
    }

    /**
     * The $Group setter method
     * @param Expression $Group 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_Group(Expression $Group)
    {
        $this->Group = $Group;
    }

    /**
     * The $Element getter method
     * @return Expression
     */
    
    public function get_Element()
    {
        return $this->Element;
    }

    /**
     * The $Element setter method
     * @param Expression $Element 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_Element(Expression $Element)
    {
        $this->Element = $Element;
    }

    /**
     * The array or object to be iterated
     * @var Expression
     */
    
    private $Group;
    
    /**
     * Variable(s) used to iterate through the elements of the object or array
     * @var type 
     */
    
    private $Element;
}

?>
